package cn.yj.web.controller.equipment;

import java.util.List;

import cn.yj.common.annotation.Log;
import cn.yj.common.core.controller.BaseController;
import cn.yj.common.core.domain.AjaxResult;
import cn.yj.common.core.page.TableDataInfo;
import cn.yj.common.enums.BusinessType;
import cn.yj.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.yj.equipment.domain.EquipInfo;
import cn.yj.equipment.service.IEquipInfoService;

/**
 * 设备信息Controller
 *
 * @author yj
 * @date 2021-03-23
 */
@Controller
@RequestMapping("/equipment/info")
public class EquipInfoController extends BaseController
{
    private String prefix = "equipment/info";

    @Autowired
    private IEquipInfoService equipInfoService;

    @RequiresPermissions("equipment:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询设备信息列表
     */
    @RequiresPermissions("equipment:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EquipInfo equipInfo)
    {
        startPage();
        List<EquipInfo> list = equipInfoService.selectEquipInfoList(equipInfo);
        return getDataTable(list);
    }

    /**
     * 导出设备信息列表
     */
    @RequiresPermissions("equipment:info:export")
    @Log(title = "设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EquipInfo equipInfo)
    {
        List<EquipInfo> list = equipInfoService.selectEquipInfoList(equipInfo);
        ExcelUtil<EquipInfo> util = new ExcelUtil<EquipInfo>(EquipInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 新增设备信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存设备信息
     */
    @RequiresPermissions("equipment:info:add")
    @Log(title = "设备信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EquipInfo equipInfo)
    {
        return toAjax(equipInfoService.insertEquipInfo(equipInfo));
    }

    /**
     * 修改设备信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        EquipInfo equipInfo = equipInfoService.selectEquipInfoById(id);
        mmap.put("equipInfo", equipInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存设备信息
     */
    @RequiresPermissions("equipment:info:edit")
    @Log(title = "设备信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EquipInfo equipInfo)
    {
        return toAjax(equipInfoService.updateEquipInfo(equipInfo));
    }

    /**
     * 删除设备信息
     */
    @RequiresPermissions("equipment:info:remove")
    @Log(title = "设备信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(equipInfoService.deleteEquipInfoByIds(ids));
    }
}
